define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'system/prop/index' + location.search,
                    add_url: 'system/prop/add',
                    edit_url: 'system/prop/edit',
                    del_url: 'system/prop/del',
                    multi_url: 'system/prop/multi',
                    import_url: 'system/prop/import',
                    table: 'system_prop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'money', title: __('Money')},
                        {field: 'num', title: __('Num')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5'),"6":__('Type 6'),"7":__('Type 7'),"8":__('Type 8')}, formatter: Table.api.formatter.normal},
                        {field: 'entity_type', title: __('Entity_type'), searchList: {"1":__('Entity_type 1'),"2":__('Entity_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'lang_type', title: __('Lang_type'), searchList: {"1":__('Lang_type 1'),"2":__('Lang_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'proptype.name', title: __('Proptype.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'chapter.name', title: __('Chapter.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'script.name', title: __('Script.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-type").on("change",function(){
                if($(this).val() == 3){
                    $(".episode_chapter_id").show();
                    $(".episode_script_id").hide();
                }else if($(this).val() == 4){
                    $(".episode_chapter_id").hide();
                    $(".episode_script_id").show();
                }else{
                    $(".episode_chapter_id").hide();
                    $(".episode_script_id").hide();
                }
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-type").on("change",function(){
                if($(this).val() == 3){
                    $(".episode_chapter_id").show();
                    $(".episode_script_id").hide();
                }else if($(this).val() == 4){
                    $(".episode_chapter_id").hide();
                    $(".episode_script_id").show();
                }else{
                    $(".episode_chapter_id").hide();
                    $(".episode_script_id").hide();
                }
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
